package com.xiao.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.xiao.gulimall.product.vo.AttrGroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiao.gulimall.product.entity.AttrGroupEntity;
import com.xiao.gulimall.product.service.AttrGroupService;
import com.xiao.common.utils.PageUtils;
import com.xiao.common.utils.R;



/**
 * 属性分组
 *
 * @author hgt
 * @email sunlightcs@gmail.com
 * @date 2021-07-20 09:30:41
 */
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list/{catId}")
    public R list(@PathVariable("catId")Long catId,@RequestParam Map<String, Object> params){
        PageUtils page = attrGroupService.queryPage(params,catId);

        return R.ok().put("page", page);
    }

    @GetMapping("/{catelogId}/withattr")
    public R getcatelogandwithattr(@PathVariable("catelogId")Long catelogId){
        List<AttrGroupVo> withattr = attrGroupService.withattr(catelogId);
        return R.ok().put("data",withattr);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
		AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);

        return R.ok().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }

}
